window.onload=function(){
    //left
    var oWhite = document.querySelectorAll('.left ul li a');
    var oCode = document.querySelector('.code');
    for(var i = 0; i < oWhite.length; i++){
        oWhite[i].index = i;
        oWhite[i].onmouseenter = function(){
            if(this.index == 10){
                oCode.style.display = "block";
            }
            for(var j = 0; j < oWhite.length; j++){
                oWhite[j].style.color = "";
            }
            oWhite[this.index].style.color = "#fff";
        }
        oWhite[i].onmouseleave = function(){
            oWhite[this.index].style.color = ""
        }
        oWhite[10].onmouseleave = function(){
            oCode.style.display = "none";
            this.style.color = "";
        }
    }
    oCode.onmouseleave = function(){
        oCode.style.display = "none";
    }
    //right
    var oRight_li=document.querySelectorAll('.right ul li');
    var oRight_a = document.querySelectorAll('.right ul li a');
    for(var i=0;i<oRight_li.length;i++){
        oRight_li[i].index=i;
        oRight_li[i].onmouseenter=function(){
            for(var j=0;j<oRight_li.length;j++){
                oRight_a[j].style.color="";
            }
            oRight_a[this.index].style.color="#fff";
        }
        oRight_li[i].onmouseleave=function(){
            oRight_a[this.index].style.color="";
        }
    }
    //注册
    var oReg = document.querySelectorAll('.right a');
    var oModal_agree = document.querySelector('.modal_agree');
    var oModal_backdrop = document.querySelector('.modal_backdrop');
    var oClose = document.querySelector('.modal_agree i');
    var oDisagree = document.getElementById('disagree');
    var oAgreeall = document.getElementById('agreeall')
    for(var i = 0; i < oReg.length; i++){
        oReg[i].index = i;
        oReg[1].onclick = function(){
            oModal_agree.style.display = "block";
            oModal_backdrop.style.display = "block";
        }
    }
    oClose.onmouseenter = function(){
        oClose.style.color = "#fff";
        oClose.style.background = "darkred";
    }
    oClose.onmouseleave = function(){
        oClose.style.color = "";
        oClose.style.background = "";
    }
    oClose.onmouseup = function(){
        oModal_agree.style.display = "none";
        oModal_backdrop.style.display = "none";
    }
    oDisagree.onmouseenter = function(){
        oDisagree.style.background = "#666";
        oDisagree.style.color = "#fff";
    }
    oDisagree.onmouseleave = function(){
        oDisagree.style.background = "";
        oDisagree.style.color = "";
    }
    oDisagree.onmouseup = function(){
        oModal_agree.style.display = "none";
        oModal_backdrop.style.display = "none";
    }
    oAgreeall.onmouseenter = function(){
        oAgreeall.style.background = "orangered";
    }
    oAgreeall.onmouseleave = function(){
        oAgreeall.style.background = "";
    }
    oAgreeall.onmouseup = function(){
        window.location.href = "register.html";
    }
    //nav
    var oNav = document.querySelectorAll('nav>ul>li>a');
    var oItemC = document.querySelectorAll('.item-children');
    for(var i = 0; i < oNav.length; i++){
        oNav[i].index = i;
        oItemC[i].index = i;
        oNav[i].onmouseenter = function(){
            for(var j = 0; j < oNav.length; j++){
                oNav[j].style.color = "";
                oItemC[j].style.display = "none";
            }
            oNav[this.index].style.color = "#f56600";
            oItemC[this.index].style.display = "block";
        }
        oNav[i].onmouseleave = function(){
            oNav[this.index].style.color = "";
            oItemC[this.index].style.display = "none";
        }
    }
    for(var i = 0; i < oItemC.length; i++){
        oItemC[i].index = i;
        oItemC[i].onmouseenter = function(){
            for(var j = 0; j < oNav.length; j++){
                oItemC[j].style.display = "none";
            }
            oNav[this.index].style.color = "#f56600";
            oItemC[this.index].style.display = "block";
        }
        oItemC[i].onmouseleave = function(){
            oItemC[this.index].style.display = "none";
            oNav[this.index].style.color = "";
        }
    }
    //搜索
    var oSearch = document.querySelector('.search');
    var oSearch_btn = document.querySelector('.icon-search');
    oSearch.onmouseenter = function(){
        oSearch.style.background = "#f56600";
        oSearch_btn.style.borderColor = "#f56600";
    }
    oSearch.onmouseleave = function(){
        oSearch.style.background = "";
        oSearch_btn.style.borderColor = "";
    }
    //分类
    var oClass = document.querySelectorAll('.class_bar>ul>li>span');
    var oClass_children = document.querySelectorAll('.class_children');
    var oUl = document.querySelectorAll('.class_children>ul');
    var num = [];
    for(var i = 0; i < oUl.length; i++){
        oUl[i].index = i;
        var count = Math.ceil(oUl[i].getElementsByTagName("li").length / 6);
        num.push(count);
    }
    for(var i = 0; i < oClass.length; i++){
        oClass[i].index = i;
        oClass_children[i].index = i;

        oClass[i].onmouseenter = function(){
            for(var j = 0; j < oClass.length; j++){
                oClass[j].style.background = "";
            }
            oClass[this.index].style.background = "#f56600";
            oClass_children[this.index].style.width = `${num[this.index] * 255}px`;
            oClass_children[this.index].style.display = "block";
        }
        oClass[i].onmouseleave = function(){
            oClass[this.index].style.background = "";
            oClass_children[this.index].style.display = "none";
        }
        oClass_children[i].onmouseenter = function(){
            oClass_children[this.index].style.display = "block";
        }
        oClass_children[i].onmouseleave = function(){
            oClass_children[this.index].style.display = "none";
        }
    }
    //透明轮播图
    var oUl=document.querySelector('.rotation ul');
    var oBox = document.querySelector('.box');
    var oUlli = document.querySelectorAll(".rotation ul li");
    var oSpan = document.querySelectorAll('.circle span');
    var timer = setInterval(autoPlay, 5000);
    var autoIndex = 0;
    var dianIndex = 0;
    function autoPlay(){
        autoIndex++;
        if(autoIndex > 4){
            autoIndex = 0;
        }
        for(var i = 0; i < oUlli.length; i++){
            animate(oUlli[i], {opacity : 0});
        }
        animate(oUlli[autoIndex], {opacity : 1});

        dianIndex++;
        if(dianIndex > 4){
            dianIndex = 0;
        }
        for(var i = 0; i < oSpan.length; i++){
            oSpan[i].className = "";
        }
        oSpan[dianIndex].className = "current";
    }

    function autoplay_left(){
        autoIndex--;
        if(autoIndex < 0 ){
            autoIndex = 4;
        }
        for(var i = 0; i < oUlli.length; i++){
            animate(oUlli[i], {opacity : 0});
        }
        animate(oUlli[autoIndex], {opacity : 1});


        dianIndex--;
        if(dianIndex < 0){
            dianIndex = 4;
        }
        for(var i = 0; i < oSpan.length; i++){
            oSpan[i].className = "";
        }
        oSpan[dianIndex].className = "current";
    }
    oBox.onmouseenter = function(){
        clearInterval(timer);
    }
    oBox.onmouseleave = function(){
        timer = setInterval(autoPlay, 5000);
    }
    //圆点轮播
    for(var i = 0; i < oSpan.length; i++){
        oSpan[i].index = i;
        oSpan[i].onclick = function(){
            autoIndex = dianIndex = this.index - 1;
            autoPlay();
        }
        if(i == 0){
            oSpan[i].className = "current";
        }
    }
    //左右轮播
    var oLeft = document.querySelector('#arrow_left');
    var oRight = document.querySelector('#arrow_right');
    oLeft.onmouseenter = function(){
        oLeft.style.background = "url('img/icon-slides.png') no-repeat 0px 50%";
    }
    oLeft.onmouseleave = function(){
        oLeft.style.background = "";
    }
    oRight.onmouseenter = function(){
        oRight.style.background = "url('img/icon-slides.png') no-repeat -41px 50%";
    }
    oRight.onmouseleave = function(){
        oRight.style.background = "";
    }
    oLeft.onclick = function(){
        autoplay_left();
    }
    oRight.onclick = function(){
        autoPlay();
    }
    //home_side
    var oHome_side=document.querySelectorAll('.home_side ul li');
    var oHome_a=document.querySelectorAll('.home_side ul li a')
    for(var i=0;i<oHome_side.length;i++){
        oHome_side[i].index=i;
        oHome_a[i].index=i;
        oHome_side[i].onmouseenter=function(){
            for(var j=0;j<oHome_side.length;j++){
                oHome_a[j].style.color="";
            }
            oHome_a[this.index].style.color="#fff";
        }
        oHome_side[i].onmouseleave=function(){
            oHome_a[this.index].style.color="";
        }
    }
    //小米闪购(倒计时)
    var oHour=document.querySelector('.hour');
    var oMinute=document.querySelector('.minute');
    var oSecond=document.querySelector('.second');
    var timer = setInterval(function(){
        var date1=new Date("2019-2-9 18:00");
        var time2=Date.now();
        var time=date1-time2;
        if(time>=0){
            var ss = parseInt(time / 1000) % 60;
            var mm = parseInt(time / 1000 / 60) % 60;
            var HH = parseInt(time / 1000 / 60 / 60) % 24;
            mm=mm<=9?"0"+mm:mm;
            ss=ss<=9?"0"+ss:ss;
            HH=HH<=9?"0"+HH:HH;
            oHour.innerHTML=HH;
            oMinute.innerHTML=mm;
            oSecond.innerHTML=ss;
            if(HH == 0 && mm == 0 && ss == 0){
                clearInterval(timer);
                oHour.innerHTML='00';
                oMinute.innerHTML='00';
                oSecond.innerHTML='00';
            }
        }else{
            oHour.innerHTML='00';
            oMinute.innerHTML='00';
            oSecond.innerHTML='00';
        }

    }, 50)
    //小米闪购(产品轮播图)
    var oMore_left=document.querySelector('.more_left');
    var oMore_right=document.querySelector('.more_right');
    var oProduct_more=document.querySelector('.product_more');
    var more_index=0;
    oMore_left.onclick=function(){
        oMore_right.style.color="#757575";
        more_index--;
        if(more_index<=0){
            oMore_left.style.color="#b0b0b0";
        }
        if(more_index<0){
            more_index=0;
            return;
        }
        animate(oProduct_more,{left:-992*more_index});
    }
    oMore_left.onmouseenter=function(){
        if(more_index>=1){
            oMore_left.style.color="#f56600";
        }
    }
    oMore_left.onmouseleave=function(){
        if(more_index>=1){
            oMore_left.style.color="#757575";
        }
    }
    oMore_right.onclick=function(){
        more_index++;
        oMore_left.style.color="#757575";
        if(more_index>=2){
            oMore_right.style.color="#b0b0b0";
        }
        if(more_index>=3){
            more_index=2;
            return;
        }
        animate(oProduct_more,{left:-992*more_index});
    }
    oMore_right.onmouseenter=function(){
        if(more_index<2){
            oMore_right.style.color="#f56600";
        }
    }
    oMore_right.onmouseleave=function(){
        if(more_index<2){
            oMore_right.style.color="#757575";
        }
    }
    //手机
    var oAll=document.querySelector('.mobile_hd>a');
    oAll.onmouseenter=function(){
        oAll.style.color="#f56600";
    }
    oAll.onmouseleave=function(){
        oAll.style.color="";
    }
    var oMobile_left=document.querySelector('.mobile_left');
    oMobile_left.onmouseenter=function(){
        oMobile_left.style.boxShadow="0px 0px 14px #757575";
        oMobile_left.style.position="relative";
        oMobile_left.style.top="-3px";
    }
    oMobile_left.onmouseleave=function(){
        oMobile_left.style.boxShadow="";
        oMobile_left.style.position="";
        oMobile_left.style.top="";
    }

    var oMobile_right=document.querySelectorAll('.mobile_right ul li');
    for(var i=0;i<oMobile_right.length;i++){
        oMobile_right[i].index=i;
        oMobile_right[i].onmouseenter=function(){
            for(var j = 0; j < oMobile_right.length; j++){
                oMobile_right[j].style.boxShadow = "";
                oMobile_right[j].style.position = "";
                oMobile_right[j].style.top = "";
            }
            oMobile_right[this.index].style.boxShadow = "0px -1px 14px #757575";
            oMobile_right[this.index].style.position="relative";
            oMobile_right[this.index].style.top="-3px";
        }
        oMobile_right[i].onmouseleave=function(){
            this.style.boxShadow = "";
            this.style.position = "";
            this.style.top = "";
        }
    }
    //家电(左边的li)
    var oEquipment_left=document.querySelectorAll('.equipment_left ul li');
    for(var i=0;i<oEquipment_left.length;i++){
        oEquipment_left[i].index=i;
        oEquipment_left[i].onmouseenter=function(){
            for(var j=0;j<oEquipment_left.length;j++){
                oEquipment_left[j].style.boxShadow="";
                oEquipment_left[j].style.position="";
                oEquipment_left[j].style.top="";
            }
            oEquipment_left[this.index].style.boxShadow="0px 0px 14px #757575";
            oEquipment_left[this.index].style.position="relative";
            oEquipment_left[this.index].style.top="-3px";
        }
        oEquipment_left[i].onmouseleave=function(){
            this.style.boxShadow="";
            this.style.position="";
            this.style.top="";
        }
    }
    //家电(右边的li)
    var oEquipment_right=document.querySelectorAll('.equipment_right ul li');
    for(var i=0;i<oEquipment_right.length;i++){
        oEquipment_right[i].index=i;
        oEquipment_right[i].onmouseenter=function(){
            for(var j = 0; j < oEquipment_right.length; j++){
                oEquipment_right[j].style.boxShadow = "";
                oEquipment_right[j].style.top = "";
            }
            oEquipment_right[this.index].style.boxShadow = "0px -1px 14px #757575";
            oEquipment_right[this.index].style.top="-3px";
        }
        oEquipment_right[i].onmouseleave=function(){
            this.style.boxShadow = "";
            this.style.top = "";
        }
    }
    //家电(tab栏切换)
    var oEquipment_hd=document.querySelectorAll('.equipment_hd ul li');
    var oEquipment_ul=document.querySelectorAll('.equipment_right ul')
    for(var i=0;i<oEquipment_hd.length;i++){
        oEquipment_hd[i].onmouseenter=(function(i){
            return function(){
                for(var j=0;j<oEquipment_hd.length;j++){
                    oEquipment_hd[j].className="";
                    oEquipment_ul[j].className="";
                }
                oEquipment_hd[i].className="current";
                oEquipment_ul[i].className="current";
            }
        })(i);
    }
    //搭配(左边的li)
    var oMarch_left=document.querySelectorAll('.martch_left ul li');
    for(var i=0;i<oMarch_left.length;i++){
        oMarch_left[i].index=i;
        oMarch_left[i].onmouseenter=function(){
            for(var j=0;j<oMarch_left.length;j++){
                oMarch_left[j].style.boxShadow="";
                oMarch_left[j].style.position="";
                oMarch_left[j].style.top="";
            }
            oMarch_left[this.index].style.boxShadow="0px 0px 14px #757575";
            oMarch_left[this.index].style.position="relative";
            oMarch_left[this.index].style.top="-3px";
        }
        oMarch_left[i].onmouseleave=function(){
            this.style.boxShadow="";
            this.style.position="";
            this.style.top="";
        }
    }
    //家电(右边的li)
    var oMarch_right=document.querySelectorAll('.martch_right ul li');
    for(var i=0;i<oMarch_right.length;i++){
        oMarch_right[i].index=i;
        oMarch_right[i].onmouseenter=function(){
            for(var j = 0; j < oMarch_right.length; j++){
                oMarch_right[j].style.boxShadow = "";
                oMarch_right[j].style.top = "";
            }
            oMarch_right[this.index].style.boxShadow = "0px -1px 14px #757575";
            oMarch_right[this.index].style.top="-3px";
        }
        oMarch_right[i].onmouseleave=function(){
            this.style.boxShadow = "";
            this.style.top = "";
        }
    }
    //家电(tab栏切换)
    var oMarch_hd=document.querySelectorAll('.martch_hd ul li');
    var oMarch_ul=document.querySelectorAll('.martch_right ul')
    for(var i=0;i<oMarch_hd.length;i++){
        oMarch_hd[i].onmouseenter=(function(i){
            return function(){
                for(var j=0;j<oMarch_hd.length;j++){
                    oMarch_hd[j].className="";
                    oMarch_ul[j].className="";
                }
                oMarch_hd[i].className="current";
                oMarch_ul[i].className="current";
            }
        })(i);
    }
    //footer
    var oService_li=document.querySelectorAll('.footer_service ul li');
    var oService_a=document.querySelectorAll('.footer_service ul li a');
    var oService_i=document.querySelectorAll('.footer_service ul li a i');
    for(var i=0;i<oService_li.length;i++){
        oService_a[i].index=i;
        oService_li[i].index=i;
        oService_i[i].index=i;
        oService_li[i].onmouseenter=function(){
            for(var j=0;j<oService_li.length;j++){
                oService_a[j].style.color="";
                oService_i[j].style.borderColor="";
            }
            oService_a[this.index].style.color="#ff6700";
            oService_i[this.index].style.borderColor="#ff6700";
        }
        oService_li[i].onmouseleave=function(){
            oService_a[this.index].style.color="";
            oService_i[this.index].style.borderColor="";
        }
    }
    //footer dd
    var oLink_a=document.querySelectorAll('.footer_link dl dd a');
    for(var i=0;i<oLink_a.length;i++){
        oLink_a[i].index=i;
        oLink_a[i].onmouseenter=function(){
            for(var j=0;j<oLink_a.length;j++){
                oLink_a[j].style.color="";
            }
            oLink_a[this.index].style.color="#ff6700";
        }
        oLink_a[i].onmouseleave=function(){
            oLink_a[this.index].style.color="";
        }
    }
    //footer contact
    var oContact_a=document.querySelector('.col_contact a');
    oContact_a.onmouseenter=function(){
        oContact_a.style.color="#fff";
        oContact_a.style.background="#ff6700";
    }
    oContact_a.onmouseleave=function(){
        oContact_a.style.color="";
        oContact_a.style.background="";
    }
    //info
    var oInfo_text=document.querySelectorAll('.info_text a');
    for(var i=0;i<oInfo_text.length;i++){
        oInfo_text[i].index=i;
        oInfo_text[i].onmouseenter=function(){
            for(var j=0;j<oInfo_text.length;j++){
                oInfo_text[j].style.color="";
            }
            oInfo_text[this.index].style.color="#ff6700";
        }
        oInfo_text[i].onmouseleave=function(){
            this.style.color="";
        }
    }
};